/*
 *  Copyright (C) 2011 JiangHongTiao <jjurco.sk_gmail.com>
 * 
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 * 
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package sk.lieskove.jianghongtiao.websearch.api.google.search;

import org.json.JSONException;
import org.json.JSONObject;

/**
 *
 * @author xjuraj
 */
class GWSResultImpl implements GWSResult{

    private JSONObject result;
    private String content;
    private String gSearchResultClass;
    private String titleNoFormatting;
    private String title;
    private String cacheUrl;
    private String unescapedUrl;
    private String url;
    private String visibleUrl;
    private int position;

    public GWSResultImpl(JSONObject result, int position) throws JSONException {
        if(result == null){
            throw new NullPointerException("JSON object is null.");
        }
        this.result = result;
        this.position = position;
        parseResult(result);
    }

    public String getGsearchResultClass() {
        return gSearchResultClass;
    }

    public String getContent() {
        return content;
    }

    public String getTitle() {
        return title;
    }

    public String getTitleNoFormatting() {
        return titleNoFormatting;
    }

    public String getCacheUrl() {
        return cacheUrl;
    }

    public String getUnescapedUrl() {
        return unescapedUrl;
    }

    public String getUrl() {
        return url;
    }

    public String getVisibleUrl() {
        return visibleUrl;
    }

    private void parseResult(JSONObject result) throws JSONException {
        content = result.getString("content");
        gSearchResultClass = result.getString("GsearchResultClass");
        titleNoFormatting = result.getString("titleNoFormatting");
        title = result.getString("title");
        cacheUrl = result.getString("cacheUrl");
        unescapedUrl = result.getString("unescapedUrl");
        url = result.getString("url");
        visibleUrl = result.getString("visibleUrl");
    }

    public int getResultPosition() {
        return position;
    }

    public void setResultPosition(int position) {
        this.position = position;
    }


}
